;
(function($) {
	var _remove = $.fn.remove;
	$.fn.remove = function() {
		$("*", this).add(this).triggerHandler("remove");
		return _remove.apply(this, arguments);
	};
	function isVisible(element) {
		function checkStyles(element) {
			var style = element.style;
			return (style.display != 'none' && style.visibility != 'hidden');
		}
		var visible = checkStyles(element);
		(visible && $.each($.dir(element, 'parentNode'), function() {
			return (visible = checkStyles(this));
		}));
		return visible;
	}
	$
			.extend(
					$.expr[':'],
					{
						data : function(a, i, m) {
							return $.data(a, m[3]);
						},
						tabbable : function(a, i, m) {
							var nodeName = a.nodeName.toLowerCase();
							return (a.tabIndex >= 0
									&& (('a' == nodeName && a.href) || (/input|select|textarea|button/
											.test(nodeName)
											&& 'hidden' != a.type && !a.disabled)) && isVisible(a));
						}
					});
	$.keyCode = {
		BACKSPACE : 8,
		CAPS_LOCK : 20,
		COMMA : 188,
		CONTROL : 17,
		DELETE : 46,
		DOWN : 40,
		END : 35,
		ENTER : 13,
		ESCAPE : 27,
		HOME : 36,
		INSERT : 45,
		LEFT : 37,
		NUMPAD_ADD : 107,
		NUMPAD_DECIMAL : 110,
		NUMPAD_DIVIDE : 111,
		NUMPAD_ENTER : 108,
		NUMPAD_MULTIPLY : 106,
		NUMPAD_SUBTRACT : 109,
		PAGE_DOWN : 34,
		PAGE_UP : 33,
		PERIOD : 190,
		RIGHT : 39,
		SHIFT : 16,
		SPACE : 32,
		TAB : 9,
		UP : 38
	};
	function getter(namespace, plugin, method, args) {
		function getMethods(type) {
			var methods = $[namespace][plugin][type] || [];
			return (typeof methods == 'string' ? methods.split(/,?\s+/)
					: methods);
		}
		var methods = getMethods('getter');
		if (args.length == 1 && typeof args[0] == 'string') {
			methods = methods.concat(getMethods('getterSetter'));
		}
		return ($.inArray(method, methods) != -1);
	}
	$.widget = function(name, prototype) {
		var namespace = name.split(".")[0];
		name = name.split(".")[1];
		$.fn[name] = function(options) {
			var isMethodCall = (typeof options == 'string'), args = Array.prototype.slice
					.call(arguments, 1);
			if (isMethodCall && options.substring(0, 1) == '_') {
				return this;
			}
			if (isMethodCall && getter(namespace, name, options, args)) {
				var instance = $.data(this[0], name);
				return (instance ? instance[options].apply(instance, args)
						: undefined);
			}
			return this
					.each(function() {
						var instance = $.data(this, name);
						(!instance && !isMethodCall && $.data(this, name,
								new $[namespace][name](this, options)));
						(instance && isMethodCall
								&& $.isFunction(instance[options]) && instance[options]
								.apply(instance, args));
					});
		};
		$[namespace][name] = function(element, options) {
			var self = this;
			this.widgetName = name;
			this.widgetEventPrefix = $[namespace][name].eventPrefix || name;
			this.widgetBaseClass = namespace + '-' + name;
			this.options = $.extend( {}, $.widget.defaults,
					$[namespace][name].defaults, $.metadata
							&& $.metadata.get(element)[name], options);
			this.element = $(element).bind('setData.' + name,
					function(e, key, value) {
						return self._setData(key, value);
					}).bind('getData.' + name, function(e, key) {
				return self._getData(key);
			}).bind('remove', function() {
				return self.destroy();
			});
			this._init();
		};
		$[namespace][name].prototype = $.extend( {}, $.widget.prototype,
				prototype);
		$[namespace][name].getterSetter = 'option';
	};
	$.widget.prototype = {
		_init : function() {
		},
		destroy : function() {
			this.element.removeData(this.widgetName);
		},
		option : function(key, value) {
			var options = key, self = this;
			if (typeof key == "string") {
				if (value === undefined) {
					return this._getData(key);
				}
				options = {};
				options[key] = value;
			}
			$.each(options, function(key, value) {
				self._setData(key, value);
			});
		},
		_getData : function(key) {
			return this.options[key];
		},
		_setData : function(key, value) {
			this.options[key] = value;
			if (key == 'disabled') {
				this.element[value ? 'addClass' : 'removeClass']
						(this.widgetBaseClass + '-disabled');
			}
		},
		enable : function() {
			this._setData('disabled', false);
		},
		disable : function() {
			this._setData('disabled', true);
		},
		_trigger : function(type, e, data) {
			var eventName = (type == this.widgetEventPrefix ? type
					: this.widgetEventPrefix + type);
			e = e || $.event.fix( {
				type : eventName,
				target : this.element[0]
			});
			return this.element.triggerHandler(eventName, [ e, data ],
					this.options[type]);
		}
	};
	$.widget.defaults = {
		disabled : false
	};
	$.ui = {
		plugin : {
			add : function(module, option, set) {
				var proto = $.ui[module].prototype;
				for ( var i in set) {
					proto.plugins[i] = proto.plugins[i] || [];
					proto.plugins[i].push( [ option, set[i] ]);
				}
			},
			call : function(instance, name, args) {
				var set = instance.plugins[name];
				if (!set) {
					return;
				}
				for ( var i = 0; i < set.length; i++) {
					if (instance.options[set[i][0]]) {
						set[i][1].apply(instance.element, args);
					}
				}
			}
		},
		cssCache : {},
		css : function(name) {
			if ($.ui.cssCache[name]) {
				return $.ui.cssCache[name];
			}
			var tmp = $('<div class="ui-gen">').addClass(name).css( {
				position : 'absolute',
				top : '-5000px',
				left : '-5000px',
				display : 'block'
			}).appendTo('body');
			$.ui.cssCache[name] = !!((!(/auto|default/).test(tmp.css('cursor'))
					|| (/^[1-9]/).test(tmp.css('height'))
					|| (/^[1-9]/).test(tmp.css('width'))
					|| !(/none/).test(tmp.css('backgroundImage')) || !(/transparent|rgba\(0, 0, 0, 0\)/)
					.test(tmp.css('backgroundColor'))));
			try {
				$('body').get(0).removeChild(tmp.get(0));
			} catch (e) {
			}
			return $.ui.cssCache[name];
		},
		disableSelection : function(el) {
			return $(el).attr('unselectable', 'on')
					.css('MozUserSelect', 'none').bind('selectstart.ui',
							function() {
								return false;
							});
		},
		enableSelection : function(el) {
			return $(el).attr('unselectable', 'off').css('MozUserSelect', '')
					.unbind('selectstart.ui');
		},
		hasScroll : function(e, a) {
			if ($(e).css('overflow') == 'hidden') {
				return false;
			}
			var scroll = (a && a == 'left') ? 'scrollLeft' : 'scrollTop', has = false;
			if (e[scroll] > 0) {
				return true;
			}
			e[scroll] = 1;
			has = (e[scroll] > 0);
			e[scroll] = 0;
			return has;
		}
	};
	$.ui.mouse = {
		_mouseInit : function() {
			var self = this;
			this.element.bind('mousedown.' + this.widgetName, function(e) {
				return self._mouseDown(e);
			});
			if ($.browser.msie) {
				this._mouseUnselectable = this.element.attr('unselectable');
				this.element.attr('unselectable', 'on');
			}
			this.started = false;
		},
		_mouseDestroy : function() {
			this.element.unbind('.' + this.widgetName);
			($.browser.msie && this.element.attr('unselectable',
					this._mouseUnselectable));
		},
		_mouseDown : function(e) {
			(this._mouseStarted && this._mouseUp(e));
			this._mouseDownEvent = e;
			var self = this, btnIsLeft = (e.which == 1), elIsCancel = (typeof this.options.cancel == "string" ? $(
					e.target).parents().add(e.target).filter(
					this.options.cancel).length
					: false);
			if (!btnIsLeft || elIsCancel || !this._mouseCapture(e)) {
				return true;
			}
			this.mouseDelayMet = !this.options.delay;
			if (!this.mouseDelayMet) {
				this._mouseDelayTimer = setTimeout(function() {
					self.mouseDelayMet = true;
				}, this.options.delay);
			}
			if (this._mouseDistanceMet(e) && this._mouseDelayMet(e)) {
				this._mouseStarted = (this._mouseStart(e) !== false);
				if (!this._mouseStarted) {
					e.preventDefault();
					return true;
				}
			}
			this._mouseMoveDelegate = function(e) {
				return self._mouseMove(e);
			};
			this._mouseUpDelegate = function(e) {
				return self._mouseUp(e);
			};
			$(document).bind('mousemove.' + this.widgetName,
					this._mouseMoveDelegate).bind('mouseup.' + this.widgetName,
					this._mouseUpDelegate);
			return false;
		},
		_mouseMove : function(e) {
			if ($.browser.msie && !e.button) {
				return this._mouseUp(e);
			}
			if (this._mouseStarted) {
				this._mouseDrag(e);
				return false;
			}
			if (this._mouseDistanceMet(e) && this._mouseDelayMet(e)) {
				this._mouseStarted = (this._mouseStart(this._mouseDownEvent, e) !== false);
				(this._mouseStarted ? this._mouseDrag(e) : this._mouseUp(e));
			}
			return !this._mouseStarted;
		},
		_mouseUp : function(e) {
			$(document).unbind('mousemove.' + this.widgetName,
					this._mouseMoveDelegate).unbind(
					'mouseup.' + this.widgetName, this._mouseUpDelegate);
			if (this._mouseStarted) {
				this._mouseStarted = false;
				this._mouseStop(e);
			}
			return false;
		},
		_mouseDistanceMet : function(e) {
			return (Math.max(Math.abs(this._mouseDownEvent.pageX - e.pageX),
					Math.abs(this._mouseDownEvent.pageY - e.pageY)) >= this.options.distance);
		},
		_mouseDelayMet : function(e) {
			return this.mouseDelayMet;
		},
		_mouseStart : function(e) {
		},
		_mouseDrag : function(e) {
		},
		_mouseStop : function(e) {
		},
		_mouseCapture : function(e) {
			return true;
		}
	};
	$.ui.mouse.defaults = {
		cancel : null,
		distance : 1,
		delay : 0
	};
})(jQuery);
(function($) {
	$
			.widget(
					"ui.colorpicker",
					{
						_init : function() {
							this.charMin = 65;
							var o = this.options, self = this, tpl = '<div class="ui-colorpicker clearfix"><div class="ui-colorpicker-color"><div><div></div></div></div><div class="ui-colorpicker-hue"><div></div></div><div class="ui-colorpicker-new-color"></div><div class="ui-colorpicker-current-color"></div><div class="ui-colorpicker-hex"><label for="ui-colorpicker-hex" title="hex"></label><input type="text" maxlength="6" size="6" id="campoCor"  disabled="disabled" /></div><div class="ui-colorpicker-rgb-r ui-colorpicker-field"><label for="ui-colorpicker-rgb-r"></label><input type="text" maxlength="3" size="2" /><span></span></div><div class="ui-colorpicker-rgb-g ui-colorpicker-field"><label for="ui-colorpicker-rgb-g"></label><input type="text" maxlength="3" size="2" /><span></span></div><div class="ui-colorpicker-rgb-b ui-colorpicker-field"><label for="ui-colorpicker-rgb-b"</label><input type="text" maxlength="3" size="2" /><span></span></div><div class="ui-colorpicker-hsb-h ui-colorpicker-field"><label for="ui-colorpicker-hsb-h"></label><input type="text" maxlength="3" size="2" /><span></span></div><div class="ui-colorpicker-hsb-s ui-colorpicker-field"><label for="ui-colorpicker-hsb-s"></label><input type="text" maxlength="3" size="2" /><span></span></div><div class="ui-colorpicker-hsb-b ui-colorpicker-field"><label for="ui-colorpicker-hsb-b"></label><input type="text" maxlength="3" size="2" /><span></span></div><button class="ui-colorpicker-submit ui-default-state" name="submit" type="button">Fechar</button></div>';
							if (typeof o.color == 'string') {
								this.color = this._HexToHSB(o.color);
							} else if (o.color.r != undefined
									&& o.color.g != undefined
									&& o.color.b != undefined) {
								this.color = this._RGBToHSB(o.color);
							} else if (o.color.h != undefined
									&& o.color.s != undefined
									&& o.color.b != undefined) {
								this.color = this._fixHSB(o.color);
							} else {
								return this;
							}
							this.origColor = this.color;
							this.picker = $(tpl);
							if (o.flat) {
								this.picker.appendTo(this.element).show();
							} else {
								this.picker.appendTo(document.body);
							}
							this.fields = this.picker.find('input').bind(
									'keydown', function(e) {
										return self._keyDown.call(self, e);
									}).bind('change', function(e) {
								return self._change.call(self, e);
							}).bind('blur', function(e) {
								return self._blur.call(self, e);
							}).bind('focus', function(e) {
								return self._focus.call(self, e);
							});
							this.picker.find('span').bind(
									'mousedown',
									function(e) {
										return self._downIncrement
												.call(self, e);
									});
							this.selector = this.picker.find(
									'div.ui-colorpicker-color')
									.bind(
											'mousedown',
											function(e) {
												return self._downSelector.call(
														self, e);
											});
							this.selectorIndic = this.selector.find('div div');
							this.hue = this.picker
									.find('div.ui-colorpicker-hue div');
							this.picker.find('div.ui-colorpicker-hue').bind(
									'mousedown', function(e) {
										return self._downHue.call(self, e);
									});
							this.newColor = this.picker
									.find('div.ui-colorpicker-new-color');
							this.currentColor = this.picker
									.find('div.ui-colorpicker-current-color');
							this.picker.find('.ui-colorpicker-submit').bind(
									'mouseenter', function(e) {
										return self._enterSubmit.call(self, e);
									}).bind('mouseleave', function(e) {
								return self._leaveSubmit.call(self, e);
							}).bind('click', function(e) {
								return self._clickSubmit.call(self, e);
							});
							this._fillRGBFields(this.color);
							this._fillHSBFields(this.color);
							this._fillHexFields(this.color);
							this._setHue(this.color);
							this._setSelector(this.color);
							this._setCurrentColor(this.color);
							this._setNewColor(this.color);
							if (o.flat) {
								this.picker.css( {
									position : 'relative',
									display : 'block'
								});
							} else {
								$(this.element).bind(
										o.eventName + ".colorpicker",
										function(e) {
											return self._show.call(self, e);
										});
							}
						},
						destroy : function() {
							this.picker.remove();
							this.element.removeData("colorpicker").unbind(
									".colorpicker");
						},
						_fillRGBFields : function(hsb) {
							var rgb = this._HSBToRGB(hsb);
							this.fields.eq(1).val(rgb.r).end().eq(2).val(rgb.g)
									.end().eq(3).val(rgb.b).end();
						},
						_fillHSBFields : function(hsb) {
							this.fields.eq(4).val(hsb.h).end().eq(5).val(hsb.s)
									.end().eq(6).val(hsb.b).end();
						},
						_fillHexFields : function(hsb) {
							this.fields.eq(0).val(this._HSBToHex(hsb)).end();
						},
						_setSelector : function(hsb) {
							this.selector.css('backgroundColor', '#'
									+ this._HSBToHex( {
										h : hsb.h,
										s : 100,
										b : 100
									}));
							this.selectorIndic.css( {
								left : parseInt(150 * hsb.s / 100, 10),
								top : parseInt(150 * (100 - hsb.b) / 100, 10)
							});
						},
						_setHue : function(hsb) {
							this.hue.css('top', parseInt(
									150 - 150 * hsb.h / 360, 10));
						},
						_setCurrentColor : function(hsb) {
							this.currentColor.css('backgroundColor', '#'
									+ this._HSBToHex(hsb));
						},
						_setNewColor : function(hsb) {
							this.newColor.css('backgroundColor', '#'
									+ this._HSBToHex(hsb));
						},
						_keyDown : function(e) {
							var pressedKey = e.charCode || e.keyCode || -1;
							if ((pressedKey >= this.charMin && pressedKey <= 90)
									|| pressedKey == 32) {
								return false;
							}
						},
						_change : function(e, target) {
							var col;
							target = target || e.target;
							if (target.parentNode.className.indexOf('-hex') > 0) {
								this.color = col = this._HexToHSB(this.value);
								this._fillRGBFields(col.color);
								this._fillHSBFields(col);
							} else if (target.parentNode.className
									.indexOf('-hsb') > 0) {
								this.color = col = this._fixHSB( {
									h : parseInt(this.fields.eq(4).val(), 10),
									s : parseInt(this.fields.eq(5).val(), 10),
									b : parseInt(this.fields.eq(6).val(), 10)
								});
								this._fillRGBFields(col);
								this._fillHexFields(col);
							} else {
								this.color = col = this._RGBToHSB(this
										._fixRGB( {
											r : parseInt(this.fields.eq(1)
													.val(), 10),
											g : parseInt(this.fields.eq(2)
													.val(), 10),
											b : parseInt(this.fields.eq(3)
													.val(), 10)
										}));
								this._fillHexFields(col);
								this._fillHSBFields(col);
							}
							this._setSelector(col);
							this._setHue(col);
							this._setNewColor(col);
							this._trigger('change', e, {
								options : this.options,
								hsb : col,
								hex : this._HSBToHex(col),
								rgb : this._HSBToRGB(col)
							});
						},
						_blur : function(e) {
							var col = this.color;
							this._fillRGBFields(col);
							this._fillHSBFields(col);
							this._fillHexFields(col);
							this._setHue(col);
							this._setSelector(col);
							this._setNewColor(col);
							this.fields.parent().removeClass(
									'ui-colorpicker-focus');
						},
						_focus : function(e) {
							this.charMin = e.target.parentNode.className
									.indexOf('-hex') > 0 ? 70 : 65;
							this.fields.parent().removeClass(
									'ui-colorpicker-focus');
							$(e.target.parentNode).addClass(
									'ui-colorpicker-focus');
						},
						_downIncrement : function(e) {
							var field = $(e.target).parent().find('input')
									.focus(), self = this;
							this.currentIncrement = {
								el : $(e.target).parent().addClass(
										'ui-colorpicker-slider'),
								max : e.target.parentNode.className
										.indexOf('-hsb-h') > 0 ? 360
										: (e.target.parentNode.className
												.indexOf('-hsb') > 0 ? 100
												: 255),
								y : e.pageY,
								field : field,
								val : parseInt(field.val(), 10)
							};
							$(document).bind('mouseup.cpSlider', function(e) {
								return self._upIncrement.call(self, e);
							});
							$(document).bind('mousemove.cpSlider', function(e) {
								return self._moveIncrement.call(self, e);
							});
							return false;
						},
						_moveIncrement : function(e) {
							this.currentIncrement.field.val(Math.max(0, Math
									.min(this.currentIncrement.max, parseInt(
											this.currentIncrement.val + e.pageY
													- this.currentIncrement.y,
											10))));
							this._change.apply(this, [ e,
									this.currentIncrement.field.get(0) ]);
							return false;
						},
						_upIncrement : function(e) {
							this.currentIncrement.el.removeClass(
									'ui-colorpicker-slider').find('input')
									.focus();
							this._change.apply(this, [ e,
									this.currentIncrement.field.get(0) ]);
							$(document).unbind('mouseup.cpSlider');
							$(document).unbind('mousemove.cpSlider');
							return false;
						},
						_downHue : function(e) {
							this.currentHue = {
								y : this.picker.find('div.ui-colorpicker-hue')
										.offset().top
							};
							this._change
									.apply(
											this,
											[
													e,
													this.fields
															.eq(4)
															.val(
																	parseInt(
																			360 * (150 - Math
																					.max(
																							0,
																							Math
																									.min(
																											150,
																											(e.pageY - this.currentHue.y)))) / 150,
																			10))
															.get(0) ]);
							var self = this;
							$(document).bind('mouseup.cpSlider', function(e) {
								return self._upHue.call(self, e);
							});
							$(document).bind('mousemove.cpSlider', function(e) {
								return self._moveHue.call(self, e);
							});
							return false;
						},
						_moveHue : function(e) {
							this._change
									.apply(
											this,
											[
													e,
													this.fields
															.eq(4)
															.val(
																	parseInt(
																			360 * (150 - Math
																					.max(
																							0,
																							Math
																									.min(
																											150,
																											(e.pageY - this.currentHue.y)))) / 150,
																			10))
															.get(0) ]);
							return false;
						},
						_upHue : function(e) {
							$(document).unbind('mouseup.cpSlider');
							$(document).unbind('mousemove.cpSlider');
							return false;
						},
						_downSelector : function(e) {
							var self = this;
							this.currentSelector = {
								pos : this.picker.find(
										'div.ui-colorpicker-color').offset()
							};
							this._change
									.apply(
											this,
											[
													e,
													this.fields
															.eq(6)
															.val(
																	parseInt(
																			100 * (150 - Math
																					.max(
																							0,
																							Math
																									.min(
																											150,
																											(e.pageY - this.currentSelector.pos.top)))) / 150,
																			10))
															.end()
															.eq(5)
															.val(
																	parseInt(
																			100 * (Math
																					.max(
																							0,
																							Math
																									.min(
																											150,
																											(e.pageX - this.currentSelector.pos.left)))) / 150,
																			10))
															.get(0) ]);
							$(document).bind('mouseup.cpSlider', function(e) {
								return self._upSelector.call(self, e);
							});
							$(document).bind('mousemove.cpSlider', function(e) {
								return self._moveSelector.call(self, e);
							});
							return false;
						},
						_moveSelector : function(e) {
							this._change
									.apply(
											this,
											[
													e,
													this.fields
															.eq(6)
															.val(
																	parseInt(
																			100 * (150 - Math
																					.max(
																							0,
																							Math
																									.min(
																											150,
																											(e.pageY - this.currentSelector.pos.top)))) / 150,
																			10))
															.end()
															.eq(5)
															.val(
																	parseInt(
																			100 * (Math
																					.max(
																							0,
																							Math
																									.min(
																											150,
																											(e.pageX - this.currentSelector.pos.left)))) / 150,
																			10))
															.get(0) ]);
							return false;
						},
						_upSelector : function(e) {
							$(document).unbind('mouseup.cpSlider');
							$(document).unbind('mousemove.cpSlider');
							return false;
						},
						_enterSubmit : function(e) {
							this.picker.find('.ui-colorpicker-submit')
									.addClass('ui-colorpicker-focus');
						},
						_leaveSubmit : function(e) {
							this.picker.find('.ui-colorpicker-submit')
									.removeClass('ui-colorpicker-focus');
						},
						_clickSubmit : function(e) {
							var col = this.color;
							this.origColor = col;
							this._setCurrentColor(col);
							this._trigger("submit", e, {
								options : this.options,
								hsb : col,
								hex : this._HSBToHex(col),
								rgb : this._HSBToRGB(col)
							});
							return false;
						},
						_show : function(e) {
							this._trigger("beforeShow", e, {
								options : this.options,
								hsb : this.color,
								hex : this._HSBToHex(this.color),
								rgb : this._HSBToRGB(this.color)
							});
							var pos = this.element.offset();
							var viewPort = this._getScroll();
							var top = pos.top + this.element[0].offsetHeight;
							var left = pos.left;
							if (top + 176 > viewPort.t
									+ Math.min(viewPort.h, viewPort.ih)) {
								top -= this.element[0].offsetHeight + 176;
							}
							if (left + 356 > viewPort.l
									+ Math.min(viewPort.w, viewPort.iw)) {
								left -= 356;
							}
							this.picker.css( {
								left : left + 'px',
								top : top + 'px'
							});
							if (this._trigger("show", e, {
								options : this.options,
								hsb : this.color,
								hex : this._HSBToHex(this.color),
								rgb : this._HSBToRGB(this.color)
							}) != false) {
								this.picker.show();
							}
							var self = this;
							$(document).bind('mousedown.colorpicker',
									function(e) {
										return self._hide.call(self, e);
									});
							return false;
						},
						_hide : function(e) {
							if (!this._isChildOf(this.picker[0], e.target,
									this.picker[0])) {
								if (this._trigger("hide", e, {
									options : this.options,
									hsb : this.color,
									hex : this._HSBToHex(this.color),
									rgb : this._HSBToRGB(this.color)
								}) != false) {
									this.picker.hide();
								}
								$(document).unbind('mousedown.colorpicker');
							}
						},
						_isChildOf : function(parentEl, el, container) {
							if (parentEl == el) {
								return true;
							}
							if (parentEl.contains && !$.browser.safari) {
								return parentEl.contains(el);
							}
							if (parentEl.compareDocumentPosition) {
								return !!(parentEl.compareDocumentPosition(el) & 16);
							}
							var prEl = el.parentNode;
							while (prEl && prEl != container) {
								if (prEl == parentEl)
									return true;
								prEl = prEl.parentNode;
							}
							return false;
						},
						_getScroll : function() {
							var t, l, w, h, iw, ih;
							if (document.documentElement) {
								t = document.documentElement.scrollTop;
								l = document.documentElement.scrollLeft;
								w = document.documentElement.scrollWidth;
								h = document.documentElement.scrollHeight;
							} else {
								t = document.body.scrollTop;
								l = document.body.scrollLeft;
								w = document.body.scrollWidth;
								h = document.body.scrollHeight;
							}
							iw = self.innerWidth
									|| document.documentElement.clientWidth
									|| document.body.clientWidth || 0;
							ih = self.innerHeight
									|| document.documentElement.clientHeight
									|| document.body.clientHeight || 0;
							return {
								t : t,
								l : l,
								w : w,
								h : h,
								iw : iw,
								ih : ih
							};
						},
						_fixHSB : function(hsb) {
							return {
								h : Math.min(360, Math.max(0, hsb.h)),
								s : Math.min(100, Math.max(0, hsb.s)),
								b : Math.min(100, Math.max(0, hsb.b))
							};
						},
						_fixRGB : function(rgb) {
							return {
								r : Math.min(255, Math.max(0, rgb.r)),
								g : Math.min(255, Math.max(0, rgb.g)),
								b : Math.min(255, Math.max(0, rgb.b))
							};
						},
						_HexToRGB : function(hex) {
							var hex = parseInt(((hex.indexOf('#') > -1) ? hex
									.substring(1) : hex), 16);
							return {
								r : hex >> 16,
								g : (hex & 0x00FF00) >> 8,
								b : (hex & 0x0000FF)
							};
						},
						_HexToHSB : function(hex) {
							return this._RGBToHSB(this._HexToRGB(hex));
						},
						_RGBToHSB : function(rgb) {
							var hsb = {};
							hsb.b = Math.max(Math.max(rgb.r, rgb.g), rgb.b);
							hsb.s = (hsb.b <= 0) ? 0 : Math.round(100
									* (hsb.b - Math.min(Math.min(rgb.r, rgb.g),
											rgb.b)) / hsb.b);
							hsb.b = Math.round((hsb.b / 255) * 100);
							if ((rgb.r == rgb.g) && (rgb.g == rgb.b))
								hsb.h = 0;
							else if (rgb.r >= rgb.g && rgb.g >= rgb.b)
								hsb.h = 60 * (rgb.g - rgb.b) / (rgb.r - rgb.b);
							else if (rgb.g >= rgb.r && rgb.r >= rgb.b)
								hsb.h = 60 + 60 * (rgb.g - rgb.r)
										/ (rgb.g - rgb.b);
							else if (rgb.g >= rgb.b && rgb.b >= rgb.r)
								hsb.h = 120 + 60 * (rgb.b - rgb.r)
										/ (rgb.g - rgb.r);
							else if (rgb.b >= rgb.g && rgb.g >= rgb.r)
								hsb.h = 180 + 60 * (rgb.b - rgb.g)
										/ (rgb.b - rgb.r);
							else if (rgb.b >= rgb.r && rgb.r >= rgb.g)
								hsb.h = 240 + 60 * (rgb.r - rgb.g)
										/ (rgb.b - rgb.g);
							else if (rgb.r >= rgb.b && rgb.b >= rgb.g)
								hsb.h = 300 + 60 * (rgb.r - rgb.b)
										/ (rgb.r - rgb.g);
							else
								hsb.h = 0;
							hsb.h = Math.round(hsb.h);
							return hsb;
						},
						_HSBToRGB : function(hsb) {
							var rgb = {};
							var h = Math.round(hsb.h);
							var s = Math.round(hsb.s * 255 / 100);
							var v = Math.round(hsb.b * 255 / 100);
							if (s == 0) {
								rgb.r = rgb.g = rgb.b = v;
							} else {
								var t1 = v;
								var t2 = (255 - s) * v / 255;
								var t3 = (t1 - t2) * (h % 60) / 60;
								if (h == 360)
									h = 0;
								if (h < 60) {
									rgb.r = t1;
									rgb.b = t2;
									rgb.g = t2 + t3;
								} else if (h < 120) {
									rgb.g = t1;
									rgb.b = t2;
									rgb.r = t1 - t3;
								} else if (h < 180) {
									rgb.g = t1;
									rgb.r = t2;
									rgb.b = t2 + t3;
								} else if (h < 240) {
									rgb.b = t1;
									rgb.r = t2;
									rgb.g = t1 - t3;
								} else if (h < 300) {
									rgb.b = t1;
									rgb.g = t2;
									rgb.r = t2 + t3;
								} else if (h < 360) {
									rgb.r = t1;
									rgb.g = t2;
									rgb.b = t1 - t3;
								} else {
									rgb.r = 0;
									rgb.g = 0;
									rgb.b = 0;
								}
							}
							return {
								r : Math.round(rgb.r),
								g : Math.round(rgb.g),
								b : Math.round(rgb.b)
							};
						},
						_RGBToHex : function(rgb) {
							var hex = [ rgb.r.toString(16), rgb.g.toString(16),
									rgb.b.toString(16) ];
							$.each(hex, function(nr, val) {
								if (val.length == 1) {
									hex[nr] = '0' + val;
								}
							});
							return hex.join('');
						},
						_HSBToHex : function(hsb) {
							return this._RGBToHex(this._HSBToRGB(hsb));
						},
						setColor : function(col) {
							if (typeof col == 'string') {
								col = this._HexToHSB(col);
							} else if (col.r != undefined && col.g != undefined
									&& col.b != undefined) {
								col = this._RGBToHSB(col);
							} else if (col.h != undefined && col.s != undefined
									&& col.b != undefined) {
								col = this._fixHSB(col);
							} else {
								return this;
							}
							this.color = col;
							this.origColor = col;
							this._fillRGBFields(col);
							this._fillHSBFields(col);
							this._fillHexFields(col);
							this._setHue(col);
							this._setSelector(col);
							this._setCurrentColor(col);
							this._setNewColor(col);
						}
					});
	$.extend($.ui.colorpicker, {
		defaults : {
			eventName : 'click',
			color : 'ff0000',
			flat : false
		}
	});
})(jQuery);